package design.leetcode_208;

import java.util.ArrayList;
import java.util.List;

public class NowcoderTrie {
    public static void main(String[] args) {
        String[][] ops = new String[][] {
                {"1", "qwer"}, {"1", "qwe"}, {"3", "qwer"}, {"4", "q"}, {"2", "qwer"}, {"3", "qwer"}, {"4", "q"}
        };
        String[] strings = new NowcoderTrie().trieU(ops);
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
    }
    public String[] trieU(String[][] operators) {
        Trie root = new Trie();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < operators.length; i++) {
            if (operators[i][0].equals("1")) {
                root.insert(operators[i][1]);
            } else if (operators[i][0].equals("2")) {
                root.delete(operators[i][1]);
            } else if (operators[i][0].equals("3")) {
                if (root.search(operators[i][1])) {
                    list.add("YES");
                } else {
                    list.add("NO");
                }
            } else {
                int count = root.prefixNumber(operators[i][1]);
                list.add(String.valueOf(count));
            }
        }
        return list.toArray(new String[0]);
    }
}
